package com.flyme.module.order.client.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 支付方式
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
@Getter
public enum PayTypeEnum implements IEnum {
    cash("cash", "现金"), Alipay("AliPay", "支付宝"), WxPay("WxPay", "微信"), Balance("Balance", "学习币"), Unionpay("Unionpay", "银联"), offline("offline", "线下支付"), WechatPay("WechatPay", "微信公众号"), iap("iap", "苹果支付");
    @EnumValue
    public String code;
    public String text;

    PayTypeEnum(String code, String text) {
        this.text = text;
        this.code = code;
    }

    PayTypeEnum(String code) {
        this.code = code;
        this.text = getText(code);
    }

    public static String getText(Object code) {
        String v = "";
        for (PayTypeEnum accountTypeEnum : PayTypeEnum.values()) {
            if (accountTypeEnum.code.equals(code)) {
                v = accountTypeEnum.text;
                break;
            }
        }
        return v;
    }

    public static PayTypeEnum getEnum(String code) {
        for (PayTypeEnum payTypeEnum : values()) {
            if (payTypeEnum.code.equals(code)) {
                return payTypeEnum;
            }
        }
        return null;
    }

    public static Map<String, Object> getMap() {
        Map<String, Object> map = new HashMap<>();
        for (PayTypeEnum payTypeEnum : values()) {
            map.put(payTypeEnum.text, payTypeEnum.code);
        }
        return map;
    }

    @Override
    public Serializable getValue() {
        return this.code;
    }
}
